package network;

import java.io.*;
import java.util.*;
import java.net.*;
import network.*;

public class ServerConn
{
    private ServerSocket serverSocket;
    private BufferedReader myInput;
    private BufferedWriter myOutput;

    public ServerConn()
    {
        // reads and creats a list of users
        try
        {
            serverSocket = new ServerSocket(1337);
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
    }

    public Socket waitConnection()
    {
        Socket temp;
        try
        {
            temp = serverSocket.accept();
        }
        catch (Exception e)
        {
            System.out.println(e);
            return null;
        }

        try
        {
            try
            {
                myInput = new BufferedReader(new InputStreamReader(temp.getInputStream()));
                myOutput = new BufferedWriter(new OutputStreamWriter(temp.getOutputStream()));
            }
            catch (Exception e)
            {
                System.out.println(e);
                return null;
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
            return null;
        }
        return temp;
    }

    public boolean sendMsg(String myString)
    {
        return Network.sendMsg(myString,myOutput);
    }

    public String recvMsg()
    {
        return recvMsg();
    }

    private boolean authUser(String user,String passwd)
    {
        // open file to read registered users
        BufferedReader fileIn = new BufferedReader(new FileReader("users.txt"));
        
        return true;
    }


/*
    public Network.ConnState getState()
    {
        return myState;
    }

    public void setState(Network.ConnState myState)
    {
        this.myState = myState;
    }
    */
}
